/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkgjeudestrategie;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author Admin
 */
//Chaque faction possède "sa" diplomatie, c'est-à-dire, ses relations avec les autres
public class Diplomatie implements Serializable{
    final static int baseValue=50;
    private ArrayList<Faction> contactedFactions=new ArrayList();
    private ArrayList<String> contactedFactionsTraite=new ArrayList();
    private ArrayList<String> contactedFactionsGuerre=new ArrayList();
    private ArrayList<String> contactedFactionsStatus=new ArrayList();// va contenir des int
  public Diplomatie(){
  } 
 // 33public int getNbOfTradingFactions(){
      
 // }
  public void addNewFaction(Faction faction){
      for(Faction f:contactedFactions){
          if(f==faction){
              return;
          }
      }
      contactedFactions.add(faction);
      contactedFactionsStatus.add(""+baseValue);
      contactedFactionsTraite.add("F");
      contactedFactionsGuerre.add("F");
  }
    public boolean askForPeace(Faction f){
        Random rnd=new Random();
        int i=rnd.nextInt(5);
        if(i==0){
            changeStatus(f, 0,1);
            
            return true;
        }
        return false;
    }
  public String statusToString(Faction faction){
      String s="Inconnu";
      int i=getStatus(faction);
      if(atWar(faction)){
              s="En guerre";
          }else if(i<40&&i>0){
              
              s="Inamical";
          }else if(i<=60&&i>=40){
              
              s="Neutre";
          }else if(i<100&&i>60){
              
              s="Amical";
          }else if(i==100){
              
              s="Allié";
          }
          
          return s;
  }
          
  public boolean atWar(Faction faction){
      int x=0;
      for(Faction f:contactedFactions){
          if(f==faction){
              
              if(contactedFactionsGuerre.get(x).equalsIgnoreCase("V")){
                  return true;
              }
          }
          x++;
      }
      return false;
  }
  public void changeStatus(Faction faction, int value, int i){
      int x=0;
      for(Faction f:contactedFactions){
          if(f==faction){
              if(i==0){
                contactedFactionsStatus.add(x,""+0);  
              }
              else if(i==1){
                  
              contactedFactionsStatus.add(x,""+25);
              }
              else{
              contactedFactionsStatus.add(x,(""+(Integer.parseInt(contactedFactionsStatus.get(x))+value)));}
              contactedFactionsStatus.remove(x+1);
              String s="";
              if(i==0||i==2){
                  s="V";
              }
              else if(i==1||i==3){
                  
                  s="F";
              }
              if(i==0||i==1){
              contactedFactionsGuerre.add(x,s);
              contactedFactionsGuerre.remove(x+1);
              }
              else if(i==2||i==3){
              contactedFactionsTraite.add(x,s);
              contactedFactionsTraite.remove(x+1);
              }
              
              
          }
          x++;
      }
  }
  public boolean isTraite(Faction faction){
      int x=0;
      for(Faction f:contactedFactions){
          if(f==faction){
              
              if(contactedFactionsTraite.get(x).equalsIgnoreCase("V")){
                  return true;
              }
          }
          x++;
      }
      return false;
  }
  public void changeStatusToAll(int value){
      int x=0;
      for(Faction f:contactedFactions){
              
              contactedFactionsStatus.add(x,(""+(Integer.parseInt(contactedFactionsStatus.get(x))+value)));
              contactedFactionsStatus.remove(x+1);
          x++;
      }
  }
  public int getStatus(Faction faction){
      int i=-1;
      int x=0;
      for(Faction f:contactedFactions){
          if(f==faction){
              
             i=Integer.parseInt(contactedFactionsStatus.get(x));
          }
          x++;
      }
      return i;
  }
}
